<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/jquery-1.11.0.js"></script>
</head>
<body>

<div>

    name: <input type="text" name="name" id="name"> <br>
    money: <input type="text" name="money" id="money"> <br>


    <button id="update">新增</button>
</div>

<script>
    $("#update").click(function (){
        //获取数据
        let name = $("#name").val();
        let money = $("#money").val();

        let account = {"name":name,"money":money}

        //发送异步请求，执行新增操作
        $.ajax({
            url:"/account",
            type:"post",
            data:JSON.stringify(account),
            contentType:"application/json",
            success:function (r){
                let code = r.code;
                if (code == 200){
                    //新增成功，跳转到首页
                    location.href = "index.html"
                }else{
                    //更新失败，提示用户
                    alert(r.msg)
                }
            },
            dataType: "json"
        })
    });
</script>
</body>
</html>